package com.codingke.codingbookstore;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Environment;

import com.codingke.codingbookstore.utils.Constant;
import com.lidroid.xutils.BitmapUtils;

import java.util.LinkedList;

import cn.bmob.v3.Bmob;

/**
 * descreption:
 * company: codingke.com
 * Created by vince on 15/11/13.
 */
public class App extends Application {

    public static Context context;
    public static BitmapUtils bitmapUtils;
    public static LinkedList<Activity> activities = new LinkedList<>();//存放所有activity的引用
    public static int screenWidth,screenHeight;

    //public static DbUtils dbUtils;
    @Override
    public void onCreate() {
        super.onCreate();
        //初始化 bmob
        Bmob.initialize(this, "4281845dc2bb39a4eda2574ff6ec884f");
        context = getApplicationContext();
        //图片缓存路径
        String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+ Constant.CACHE_PATH;
        bitmapUtils = new BitmapUtils(this,path);
        bitmapUtils.configDefaultBitmapMaxSize(100,100);
        bitmapUtils.configDefaultLoadingImage(R.mipmap.logo);

        //dbUtils = DbUtils.create(context,Constant.DB_NAME);
        //测试内存泄露
//        refWatcher = LeakCanary.install(this);
    }
//    private RefWatcher refWatcher;
//    public static RefWatcher getRefWatcher(Context context) {
//        App application = (App) context.getApplicationContext();
//        return application.refWatcher;
//    }

    public static void release(){
        bitmapUtils = null;
        activities = null;
        context = null;
    }

}
